//
//  KADetailSectionHeaderView.m
//  KeepAccount
//
//  Created by Veer on 2017/12/19.
//  Copyright © 2017年 Veer. All rights reserved.
//

#import "KADetailSectionHeaderView.h"

#import "KAAccountSectionModel.h"
#import "NSString+Tools.h"

@interface KADetailSectionHeaderView()

/** 日期 */
@property (nonatomic, weak) UILabel *dateLbl;
/** 支出 */
@property (nonatomic, weak) UILabel *moneyLbl;
/** 日期 */
@property (nonatomic, weak) UIView *bottomLineView;

@end

@implementation KADetailSectionHeaderView

+ (instancetype)headerViewWith:(UITableView *)tableview
{
    static NSString *cellID = @"KADetailSectionHeaderView";
    
    KADetailSectionHeaderView *cell = [tableview dequeueReusableHeaderFooterViewWithIdentifier:cellID];
    if (nil == cell) {
        
        cell = [[KADetailSectionHeaderView alloc] initWithReuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupSubView];
    }
    return self;
}

- (void)setupSubView
{
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    // 日期
    UILabel *dateLbl = [[UILabel alloc] init];
    dateLbl.text = @"12月17日 星期日";
    dateLbl.font = [UIFont systemFontOfSize:14];
    dateLbl.textColor = RGB(162, 162, 162);
    [self.contentView addSubview:dateLbl];
    self.dateLbl = dateLbl;
    [dateLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.left.mas_equalTo(15);
    }];
    
    // 金额
    UILabel *moneyLbl = [[UILabel alloc] init];
    moneyLbl.text = @"支出：50";
    moneyLbl.font = [UIFont systemFontOfSize:14];
    moneyLbl.textColor = RGB(162, 162, 162);
    moneyLbl.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:moneyLbl];
    self.moneyLbl = moneyLbl;
    [moneyLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.right.mas_equalTo(-15);
    }];
    
    // 线
    UIView *hLineView = [[UIView alloc] init];
    hLineView.backgroundColor = RGB(225, 225, 225);
    [self.contentView addSubview:hLineView];
    self.bottomLineView = hLineView;
    [hLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.contentView);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
}

#pragma mark - setter && getter
- (void)setAccountSectionModel:(KAAccountSectionModel *)accountSectionModel
{
    _accountSectionModel = accountSectionModel;
    
    self.dateLbl.text = accountSectionModel.formatDate;
    
    if (accountSectionModel.income > 0 && accountSectionModel.expenditure > 0) {
        
        self.moneyLbl.text = [NSString stringWithFormat:@"收入：%@  支出：%@", [NSString moneyWith:accountSectionModel.income], [NSString moneyWith:accountSectionModel.expenditure]];
    }else if (accountSectionModel.income > 0){
        
        self.moneyLbl.text = [NSString stringWithFormat:@"收入：%@", [NSString moneyWith:accountSectionModel.income]];
    }else if (accountSectionModel.expenditure > 0){
        
        self.moneyLbl.text = [NSString stringWithFormat:@"支出：%@", [NSString moneyWith:accountSectionModel.expenditure]];
    }
}

@end
